# Table D1: Covid-19 Unemployment Effects on Asian Hate Crimes: Accounting for the Size of East and Southeast Asian Communities

rm(list = ls())

setwd('/path/to/replication/')

library(data.table)
library(estimatr)
library(texreg)

load('./data/panel_month_dummies.RData')
panelu <- panel[!is.na(share_asian_immigrant)]

out_econ_simple <- lm_robust(hc_pc_asians ~ covid2*losing_income_d,
                                              data=panelu, se_type='stata',
                                              clusters = panelvar)

if (!file.exists('./output/out_econ_immigrant_covars.RData') &
    !file.exists('./output/out_econ_con_immigrant_covars.RData') &
    !file.exists('./output/out_econ_con_trend_immigrant_covars.RData') &
    !file.exists('./output/out_econ_con_trend_all_immigrant_covars.RData')) {
  source('./code/tableD1reg.R')
}

out_econ <- get(load('./output/out_econ_immigrant_covars.RData'))
out_econ_con <- get(load('./output/out_econ_con_immigrant_covars.RData'))
out_econ_con_trend <- get(load('./output/out_econ_con_trend_immigrant_covars.RData'))
out_econ_con_trend_all <- get(load('./output/out_econ_con_trend_all_immigrant_covars.RData'))

tabled1 <- texreg(list(out_econ_simple, out_econ, out_econ_con, out_econ_con_trend, out_econ_con_trend_all),
       include.ci = FALSE,
       include.adjrs = FALSE, include.rmse = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1), digits = 5,
       custom.coef.map = list('losing_income_d' = 'Expected unemployment', 'covid2'= 'After Jan, 2020', 
                              'covid2:losing_income_d' = 'After Jan, 2020 x Expected unemployment',
                              'covid_econ' = 'After Jan, 2020 x Expected unemployment'),
       symbol = "\\circ",
       caption = "Covid-19 Unemployment Effects on Asian Hate Crimes: Accounting for the Size of East and Southeast Asian Communities",
       caption.above = TRUE)

write(tabled1, file.path('./tableD1.tex'))
